package com.liang.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class PoolDemo {
    public static void main(String[] args) throws InterruptedException {

        //创建线程池服务对象
        ExecutorService executorService = Executors.newCachedThreadPool();

        //调用对象的submit提交任务的方法，方法执行完毕，线程回归线程池
        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName()+"执行了");
        });

//        Thread.sleep(2000);

        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName()+"执行了");
        });

        //关闭线程池对象
        executorService.shutdown();
    }
}
